package util

import (
	"strconv"
	"fmt"
	"strings"
	log "code.google.com/p/log4go"
)
/**
	将String类型转换为int类型
 */
func StrConverToInt(n string) (int,error) {
	v,err:=strconv.Atoi(n)
	if err != nil {
		return 0,err
	}
	return v,nil
}
/**
	转为String,针对配置类中的各种类型：
 */
func ToString(args ...interface{}) string {
	result := ""
	for _, arg := range args {
		switch val := arg.(type) {
			case int:
				result += strconv.Itoa(val)
			case string:
				result += val
			case int64:
				result += strconv.FormatInt(val, 10)
			case int8, int16, int32, uint8, uint16, uint32, uint64, uint, uintptr:
				result += fmt.Sprintf("%v", val)
			case bool:
				result += strconv.FormatBool(val)
			case float32:
				result += fmt.Sprintf("%v", val)
			case float64:
				result += fmt.Sprintf("%v", val)
		}
	}
	return result
}

/**
	转成小写
 */
func ToLowerCase(src string)string{
	return strings.ToLower(src)
}

/**
 	将String 类型转化为Bool类型
  */
func ToBool(value string,defaultvalue bool) (v bool){
	result,err := strconv.ParseBool(value)
	if err!= nil {
		log.Error(err)
		return defaultvalue
	}
	return result
}